#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
@file:BasePlugin.py
@time:2017/7/20 0020 16:37
"""
import paramiko
import config
import subprocess
class BasePlugin(object):
    def __init__(self):
        pass
    def exec_shell_cmd(self,cmd):
        '''
        private_key_path = config.configration['key_path']
        key = paramiko.RSAKey.from_private_key_file(private_key_path)
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(hostname=self.hostname,port=self.port,username=self.username,pkey=key)
        stdin,stdout,stderr = self.exec_shell_cmd(cmd)
        result = stdout.read()
        ssh.close()
        '''
        status,output = subprocess.getstatusoutput(cmd)
        return output
    def os_platform(self):
        output = self.exec_shell_cmd('uname')
        return output.strip()
    def os_version(self):
        try:
            output = self.exec_shell_cmd('cat /etc/issue')
            result = output.strip().split('\n')[0]
        except Exception as e:
            result = " "
        return result
    def os_hostname(self):
        output = self.exec_shell_cmd('hostname')
        return output.strip()
    def linux(self):
        raise Exception('You must implement Linux method.')
    def windows(self):
        raise Exception('You must implement Windows method.')
    def execute(self):
        return self.linux()
'''
class NicPlugin(BasePlugin):
    #重写Linux方法
    def linux(self):
        self.exec_shell_cmd('cmd')
obj = NicPlugin()
#调用execute方法获取数据。
obj.execute()
'''